package com.example.springboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    // 当前跨域请求最大有效时长。这里默认1天
   @Override
    public void addCorsMappings(CorsRegistry registry){
       registry.addMapping("/**")
               .allowedOriginPatterns("*")
               .allowCredentials(true)
               .allowedOrigins("http://localhost")
               .allowedMethods("*")
               .allowedHeaders("*")
               .maxAge(3600);
   }
}
